<?php
/**
 * 婚礼页面管理
 * @author cjli
 *
 */
class GroupBuyingAction extends HomeAction
{
	public function _initialize()
	{
		parent::_initialize();
	}
	
	public function wedding()
	{
		global $language_id;

    	$data = array(
    		'docTitle' => L('wedding_docTitle'),
    		'docKeywords' => L('wedding_docKeywords'),
    		'docDescription' => L('wedding_docDescription'),
    	);
    	$this->assign($data);
		$this->assign('canonical' ,url('/groupBuying/wedding/index'));		
		//西服
		$suitIdArr = '391,878,393,803,389,744,749,175,668,671,844,838,497';
		$suitIdArr = explode(',', $suitIdArr);
		//衬衫
		$shirtIdArr = '702,765,763,666,662,704,376,379,382,380';
		$shirtIdArr = explode(',', $shirtIdArr);
		//领结 袖口
		$accessoriesCatid = '2076,2077,2079';
		$accessoriesCatid = explode(',', $accessoriesCatid);		
		//方巾、胸针
		$broochIdArr = '250,253,252,255,251,228,229,227,230,226,246,597,598,247,599,276,259,272,268,273';
		$broochIdArr = explode(',', $broochIdArr);

		
		$productList['suit'] = ProductModel::get_product_collection_list($suitIdArr,$language_id);
		$productList['shirt'] = ProductModel::get_product_collection_list($shirtIdArr,$language_id);
		$productList['accessories'] = array();
/*		foreach($accessoriesCatid as $catid){
		   $cartProList  = ProductModel::get_product_list(array('catid'=>$catid));
		   $productList['accessories'] = array_merge ($productList['accessories'],$cartProList); 		    
		}*/
		$brooch = ProductModel::get_product_collection_list($broochIdArr,$language_id);
		$productList['accessories'] = array_merge ($productList['accessories'],$brooch); 
		
	    //echo "<pre />";print_r($productList);exit;
		
		$this->assign('productList',$productList);
		$this->display('group-buying/wedding/index');
	}
    
    //提交婚礼留言信息
	public function formpost()
	{   
		$type = $this->_post('type');
	    $data = array(
                'name'       => $this->_post('name'),
                'email'      => $this->_post('email'),
                'message'    => $this->_post('message'),
                'creat_time' => time(),
	    );	 
	    // echo "<pre />";
	    // print_r($_POST);	
	    $msgStr = 1;
	    if($type == 'contact'){
            $data['type'] = 0;
            //内部邮件
            $sendMail = 'service@ownonly.net';
            $title = 'Wedding Refer Us & Partnership';
            $content  = 'Name:'.$data['name'].'<br />';
			$content .= 'Email: &nbsp;'.$data['email'].'<br />';
			$content .= 'Message:'.$data['message'].'<br />';	
	    }else if($type == 'wedding'){
	    	$data['phone']        = $this->_post('phone');
	    	$data['call_back']    = $this->_post('call_back');
	    	$data['wedding_date'] = strtotime($this->_post('wedding_date'));
	    	$data['formal_count'] = $this->_post('formalCount');
	    	$data['type'] = 1;
	    	//内部邮件
	    	$sendMail = 'service@ownonly.net';
            $title = 'Wedding Group Order';
            $content  = 'Name:'.$data['name'].'<br />';
			$content .= 'Email: &nbsp;'.$data['email'].'<br />';
			$content .= 'Phone:'.$data['phone'].'<br />';
			$content .= 'Wedding Date:'.date('M jS,Y',$data['wedding_date']).'<br />';
			$checked  = $data['call_back'] ? 'checked':'';
			$content .= '<input type="checkbox" '.$checked.' disabled />request a call back'.'<br />';
			$content .= 'Wedding Party Size:'.$data['formal_count'].'<br />';
			$content .= 'Message:'.$data['message'].'<br />';    	
	    }else if($type == 'group_contact'){
            $data['type'] = 2;
            //内部邮件
            $sendMail = 'service@ownonly.net';
            $title = 'Make Money By Referring Us';
            $content  = 'Name:'.$data['name'].'<br />';
			$content .= 'Email:&nbsp;'.$data['email'].'<br />';
			$content .= 'Message:'.$data['message'].'<br />';	
	    }else if($type == 'group'){

            //附件
			import('ORG.Net.UploadFile');
			$upload = new UploadFile();// 实例化上传类
			$upload->maxSize  = 3145728 ;// 设置附件上传大小
			$upload->savePath =  '.'.UPLOAD_PATH;
			$upload->autoSub = true;
			$upload->subType = 'custom';			
			$upload->subDir = 'upload/';	
			if($upload->upload()){
			    $info =  $upload->getUploadFileInfo();var_dump($info);
                $path = $info['0']['savepath'].$info['0']['savename'];
                $path = trim($path,'.');			    
			    $data['message'] .= '<br /><br /><b>Upload Files</b>:<a href="http://'.$_SERVER["HTTP_HOST"].$path.'" target="_blank">'.$info['0']['name'].'</a>';
			}

	    	$data['phone']        = $this->_post('phone');
	    	$data['call_back']    = $this->_post('call_back') ? 1 : 0;
	    	$data['formal_count'] = $this->_post('formalCount');
	    	$data['type'] = 3;
	    	//内部邮件
	    	$sendMail = 'service@ownonly.net';
            $title = 'GROUP ORDER CONTACT';
            $content  = 'Name:'.$data['name'].'<br />';
			$content .= 'Email: &nbsp;'.$data['email'].'<br />';
			$content .= 'Phone:'.$data['phone'].'<br />';
			$checked  = $data['call_back'] ? 'checked':'';
			$content .= '<input type="checkbox" '.$checked.' disabled />request a call back'.'<br />';
			$content .= 'Group Order Size:'.$data['formal_count'].'<br />';
			$content .= 'Message:'.$data['message'].'<br />';    	
	    }else if($type == 'partner'){
            $post =  $_POST;
            //合并到message字段
			$message  = 'COMPANY NAME: '.$this->_post('company_name').'<br />';
			$message .= 'BUSINESS WEBSITE: '.$this->_post('business_website').'<br />';
			$message .= 'COMPANY EMPLOYEES: '.$this->_post('company_employees').'<br />';
			$message .= 'COUNTRY: '.$this->_post('country').'<br />';
			$message .= 'ANNUAL REVENUE: '.$this->_post('annual_revenue').'<br />';
			$message .= 'INTRODUCE YOUR BUSINESS: '.$this->_post('business_introduce').'<br />';
			$message .= 'HOW DO YOU WANT TO WORK WITH US: '.$this->_post('work_plan').'<br />';
			$data['message'] = $message;
			$data['phone'] = $this->_post('phone');
            $data['type'] = 4;            
            //合作伙伴
            $sendMail = 'service@ownonly.net';
            $title = 'OWNONLY Partner Application';
            $content  = 'NAME:'.$data['name'].'<br />';
			$content .= 'EMAIL:&nbsp;'.$data['email'].'<br />';
			$content .= 'PHONE:'.$data['phone'].'<br />';
            $content .= $message;
	    }else{
	        $msgStr = 0;
	    }
	    if($msgStr == 1){
		    $data['title'] = $title;
		    $res = M('wedding_msg')->add($data);
		    if($res){
				$mailInstance = new EmailModel();
				$mailInstance->sendMail($sendMail, $title, $content);  	
		    	$msgStr = 1;
		    }else{
		    	$msgStr = 0;
		    }
	    }
		if($type == 'group'){
			echo '<script>window.parent.toshow('.$msgStr.')</script>';exit;
		}else{
			echo $msgStr;
		}	  		
	}
	
	public function group()
	{
		global $language_id;

    	$data = array(
    		'docTitle' => 'Group Orders Of Men Custom Suit | OWNONLY ',
    		'docKeywords' => '',
    		'docDescription' => '',
    	);
    	$this->assign($data);			
		
		//西服
		$suitIdArr = '744,55,692,173,175,180,170,795,745,693';
		$suitIdArr = explode(',', $suitIdArr);
		//衬衫
		$shirtIdArr = '122,159,118,307,115,300,702,704,106,123';
		$shirtIdArr = explode(',', $shirtIdArr);
		//方巾、胸针
		$accessoriesIdArr = '250,228,293,226,248';
		$accessoriesIdArr = explode(',', $accessoriesIdArr);

		$productList['suit'] = ProductModel::get_product_collection_list($suitIdArr,$language_id);
		$productList['shirt'] = ProductModel::get_product_collection_list($shirtIdArr,$language_id);
		$productList['accessories'] = ProductModel::get_product_collection_list($accessoriesIdArr,$language_id);
		
		$this->assign('productList',$productList);
		$this->display('group-buying/group/index');
	}
    
}